package com.ruoyi.smartcity.traffic.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.smartcity.traffic.domain.TrafficFlow;
import com.ruoyi.smartcity.traffic.service.ITrafficFlowService;
import com.ruoyi.smartcity.traffic.service.ITrafficRoadInformationService;
import com.ruoyi.smartcity.traffic.service.ITrafficRoadStateService;
import com.ruoyi.smartcity.traffic.vo.EchartsOptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author harry
 * @公众号 Harry技术
 */
@RestController
@RequestMapping("/smartcity/traffic/index")
public class IndexController {
    @Autowired
    private ITrafficRoadStateService trafficRoadStateService;
    @Autowired
    private ITrafficRoadInformationService trafficRoadInformationService;
    @Autowired
    private ITrafficFlowService trafficFlowService;

    /**
     * roadStateCounts  路况数据
     * roadCounts 道路数量
     *
     * @return
     */
    @GetMapping("/dataCounts")
    public AjaxResult dataCounts() {
        Map<String, Long> dataCounts = new HashMap<>(16);
        dataCounts.put("roadStateCounts", trafficRoadStateService.count());
        dataCounts.put("roadCounts", trafficRoadInformationService.count());
        return AjaxResult.success(dataCounts);
    }

    // 道路车流量top10
    @GetMapping("/top10")
    public AjaxResult top10() {
        EchartsOptionVO trafficFlows = trafficFlowService.top10();
        return AjaxResult.success(trafficFlows);
    }

    // 某一时间道路车流量数
    @GetMapping("/analysisByTime")
    public AjaxResult analysisByTime() {
        EchartsOptionVO trafficFlows = trafficFlowService.analysisByTime();
        return AjaxResult.success(trafficFlows);
    }

    // 道路累计车流量数据
    @GetMapping("/analysisAccumulate")
    public AjaxResult analysisAccumulate() {
        List<Map<String, Object>> map = trafficFlowService.analysisAccumulate();
        return AjaxResult.success(map);
    }

    // 平均车速
    @GetMapping("/averageSpeed")
    public AjaxResult averageSpeed() {
        List<Map<String, Object>> map = trafficFlowService.averageSpeed();
        return AjaxResult.success(map);
    }

    // 行程时间
    @GetMapping("/travelTime")
    public AjaxResult travelTime() {
        EchartsOptionVO trafficFlows = trafficFlowService.travelTime();
        return AjaxResult.success(trafficFlows);
    }
}
